//
//  commonTool.swift
//  压岁_IOS
//
//  Created by 梓简王 on 2017/7/12.
//  Copyright © 2017年 梓简王. All rights reserved.
//

import Foundation
import UIKit

class commonTool {
    static func getColorWithRGB(red:Int,green:Int,blue:Int,alpha:CGFloat)->UIColor{
        return UIColor(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: alpha)
    }
    
    static func initLoginBtn(initStr:NSString,rect:CGRect,center:CGPoint)->UIButton{
        let tempBtn = UIButton.init(frame: rect)
        tempBtn.setTitle(initStr as String, forState: UIControlState.Normal)
        tempBtn.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
        tempBtn.titleLabel?.font = UIFont.init(name: commonVariable.CHINAFONTNAME, size: 14)
        tempBtn.backgroundColor = UIColor.init(red: 0.000, green: 0.294, blue: 0.624, alpha: 1.000)
        if(center != CGPoint(x: 0, y: 0)){
            tempBtn.center = center
        }
        tempBtn.layer.cornerRadius = 5
        tempBtn.clipsToBounds = true
        return tempBtn
    }
    static func getUnixTime()->String{
        let date = NSDate()
        let timeInterval = date.timeIntervalSince1970 * 1000
        return "\(timeInterval)"
    }
    static func dic2Json(dict:[String:Any])->NSString{
        let data:NSData?
        let strJson:NSString?
        do {
            data = try NSJSONSerialization.dataWithJSONObject(dict as! [String:String], options: NSJSONWritingOptions.PrettyPrinted)
            strJson=NSString(data: data!, encoding: NSUTF8StringEncoding)
            return strJson!
        } catch {
            print("发生错误")
        }
        return ""
    }
}